package parameter;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.TextField;
import java.util.ArrayList;

import javax.swing.ImageIcon;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import javax.swing.JTree;
import javax.swing.border.EmptyBorder;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.JScrollPane;

import parameter.crop.ActuImpCrop1;
import parameter.crop.ActuImpCrop3;
import parameter.crop.ActuTraCrop1;
import parameter.crop.ActuTraCrop3;
import parameter.crop.AutoImpCrop1;
import parameter.crop.AutoImpCrop3;
import parameter.crop.AutoTraCrop1;
import parameter.crop.AutoTraCrop3;

import java.awt.Font;
import java.awt.SystemColor;

public class ParaManage extends JFrame {
	private JPanel contentPane;
	private ArrayList<JTabbedPane> tabs; // 选项卡数组，为了实现显示和隐藏选项卡

	/**
	 *  @author by liangtingting
	 */
	public ParaManage() throws Exception {
		// TODO Auto-generated constructor stub
		setVisible(true);
		this.setDefaultCloseOperation(this.DISPOSE_ON_CLOSE);
		
		setBounds(100, 100, 733, 482);
		setTitle("管理控制区");
		tabs = new ArrayList<>();
		contentPane = new JPanel();
		contentPane.setFont(new Font("宋体", Font.PLAIN, 12));
	
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		GridBagLayout gbl_contentPane = new GridBagLayout();
		gbl_contentPane.columnWidths = new int[] { 707, 0 };
		gbl_contentPane.rowHeights = new int[] { 434, 0 };
		gbl_contentPane.columnWeights = new double[] { 0.0, Double.MIN_VALUE };
		gbl_contentPane.rowWeights = new double[] { 0.0, Double.MIN_VALUE };
		contentPane.setLayout(gbl_contentPane);
		JTabbedPane tabbedPanes = new JTabbedPane(JTabbedPane.TOP);
		tabbedPanes.setFont(new Font("宋体", Font.PLAIN, 12));
		GridBagConstraints gbc_tabbedPanes = new GridBagConstraints();
		gbc_tabbedPanes.fill = GridBagConstraints.BOTH;
		gbc_tabbedPanes.gridx = 0;
		gbc_tabbedPanes.gridy = 0;
		contentPane.add(tabbedPanes, gbc_tabbedPanes);

		final JScrollPane scrollPane;

		DefaultMutableTreeNode fCOption = new DefaultMutableTreeNode("功能选项");
		DefaultMutableTreeNode Coption1 = new DefaultMutableTreeNode("自动灌溉控制");
		DefaultMutableTreeNode Coption2 = new DefaultMutableTreeNode("实际蒸腾估算");
		DefaultMutableTreeNode Cway1_1 = new DefaultMutableTreeNode("根区算术平均法");
		DefaultMutableTreeNode Cway1_2 = new DefaultMutableTreeNode("根区加权平均法");
		final DefaultMutableTreeNode Csensor1_1_1 = new DefaultMutableTreeNode(
				"土壤水分传感器");
		final DefaultMutableTreeNode Csensor1_1_3 = new DefaultMutableTreeNode(
				"土壤水盐传感器");
		final DefaultMutableTreeNode Csensor1_2_1 = new DefaultMutableTreeNode(
				"土壤水分传感器");
		final DefaultMutableTreeNode Csensor1_2_3 = new DefaultMutableTreeNode(
				"土壤水盐传感器");
		 DefaultMutableTreeNode Cway2_1 = new DefaultMutableTreeNode("根区算术平均法");
		 DefaultMutableTreeNode Cway2_2 = new DefaultMutableTreeNode("根区加权平均法");
		final DefaultMutableTreeNode Csensor2_1_1 = new DefaultMutableTreeNode(
				"土壤水分传感器");
		final DefaultMutableTreeNode Csensor2_1_3 = new DefaultMutableTreeNode(
				"土壤水盐传感器");
		final DefaultMutableTreeNode Csensor2_2_1 = new DefaultMutableTreeNode(
				"土壤水分传感器");
		final DefaultMutableTreeNode Csensor2_2_3 = new DefaultMutableTreeNode(
				"土壤水盐传感器");
		DefaultTreeModel Coption = new DefaultTreeModel(fCOption);
		fCOption.add(Coption1);
		fCOption.add(Coption2);
		Cway1_1.add(Csensor1_1_1);
		Cway1_1.add(Csensor1_1_3);
		Cway1_2.add(Csensor1_2_1);
		Cway1_2.add(Csensor1_2_3);
		Coption1.add(Cway1_1);
		Coption1.add(Cway1_2);
		
		
		Cway2_1.add(Csensor2_1_1);
		
		Cway2_1.add(Csensor2_1_3);
		Cway2_2.add(Csensor2_2_1);
		Cway2_2.add(Csensor2_2_3);
		Coption2.add(Cway2_1);
		Coption2.add(Cway2_2);
		final JTree Ctree = new JTree(Coption);
		Ctree.setRowHeight(25);
		Ctree.setFont(new Font("宋体", Font.PLAIN, 12));
		scrollPane = new JScrollPane(Ctree);
		scrollPane.setFont(new Font("宋体", Font.PLAIN, 12));
		tabbedPanes.addTab("作物参数", null, scrollPane, null);
		tabbedPanes.setForegroundAt(0, SystemColor.desktop);
		Ctree.addTreeSelectionListener(new TreeSelectionListener() {
        
			@Override
			public void valueChanged(TreeSelectionEvent e) {
				// TODO Auto-generated method stub
				Object selectObject = Ctree.getLastSelectedPathComponent();
				Ctree.clearSelection();
				
				if (selectObject == Csensor1_1_1) {
					try {
						
						new AutoTraCrop1();
					
					} catch (Exception e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
				}
				else if(selectObject == Csensor1_1_3){
					try {
						
						new AutoTraCrop3();
						
					} catch (Exception e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
				}
				else if(selectObject == Csensor1_2_1){
					try {
						
						new AutoImpCrop1();
						
					} catch (Exception e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}	
				}
				else if(selectObject == Csensor1_2_3){
					try {
						
						new AutoImpCrop3();
						
					} catch (Exception e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}	
				}
				else if (selectObject == Csensor2_1_1) {
					try {
						
						new ActuTraCrop1();
						
					} catch (Exception e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
				}
				else if(selectObject == Csensor2_1_3){
					try {
						
						new ActuTraCrop3();
						
					} catch (Exception e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
				}
				else if(selectObject == Csensor2_2_1){
					try {
						
						new ActuImpCrop1();
						
					} catch (Exception e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}	
				}
				else if(selectObject == Csensor2_2_3){
					try {
						
						new ActuImpCrop3();
						
					} catch (Exception e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}	
				}

			}
		});

		DefaultMutableTreeNode fSOption = new DefaultMutableTreeNode("功能选项");
		DefaultMutableTreeNode Soption1 = new DefaultMutableTreeNode("自动灌溉控制");
		DefaultMutableTreeNode Soption2 = new DefaultMutableTreeNode("实际蒸腾估算");
		DefaultMutableTreeNode Sway1_1 = new DefaultMutableTreeNode("根区算术平均法");
		DefaultMutableTreeNode Sway1_2 = new DefaultMutableTreeNode("根区加权平均法");
		DefaultMutableTreeNode Ssensor1_1_1 = new DefaultMutableTreeNode(
				"土壤水分传感器");
		DefaultMutableTreeNode Ssensor1_1_3 = new DefaultMutableTreeNode(
				"土壤水盐传感器");
		DefaultMutableTreeNode Ssensor1_2_1 = new DefaultMutableTreeNode(
				"土壤水分传感器");
		DefaultMutableTreeNode Ssensor1_2_3 = new DefaultMutableTreeNode(
				"土壤水盐传感器");
		DefaultMutableTreeNode Sway2_1 = new DefaultMutableTreeNode("根区算术平均法");
		DefaultMutableTreeNode Sway2_2 = new DefaultMutableTreeNode("根区加权平均法");
		DefaultMutableTreeNode Ssensor2_1_1 = new DefaultMutableTreeNode(
				"土壤水分传感器");
		DefaultMutableTreeNode Ssensor2_1_3 = new DefaultMutableTreeNode(
				"土壤水盐传感器");
		DefaultMutableTreeNode Ssensor2_2_1 = new DefaultMutableTreeNode(
				"土壤水分传感器");
		DefaultMutableTreeNode Ssensor2_2_3 = new DefaultMutableTreeNode(
				"土壤水盐传感器");
		DefaultTreeModel Soption = new DefaultTreeModel(fSOption);
		fSOption.add(Soption1);
		fSOption.add(Soption2);
		Sway1_1.add(Ssensor1_1_1);
		Sway1_1.add(Ssensor1_1_3);
		Sway1_2.add(Ssensor1_2_1);
		Sway1_2.add(Ssensor1_2_3);
		Soption1.add(Sway1_1);
		Soption1.add(Sway1_2);
		Sway2_1.add(Ssensor2_1_1);
		Sway2_1.add(Ssensor2_1_3);
		Sway2_2.add(Ssensor2_2_1);
		Sway2_2.add(Ssensor2_2_3);
		Soption2.add(Sway2_1);
		Soption2.add(Sway2_2);
		JTree Stree = new JTree(Soption);
		Stree.setFont(new Font("宋体", Font.PLAIN, 12));
		JScrollPane scrollPane_1 = new JScrollPane(Stree);
		scrollPane_1.setFont(new Font("宋体", Font.PLAIN, 12));
		tabbedPanes.addTab("土壤参数", null, scrollPane_1, null);

		DefaultMutableTreeNode fFOption = new DefaultMutableTreeNode("功能选项");
		DefaultMutableTreeNode Foption1 = new DefaultMutableTreeNode("自动灌溉控制");
		DefaultMutableTreeNode Foption2 = new DefaultMutableTreeNode("实际蒸腾估算");
		DefaultMutableTreeNode Fway1_1 = new DefaultMutableTreeNode("根区算术平均法");
		DefaultMutableTreeNode Fway1_2 = new DefaultMutableTreeNode("根区加权平均法");
		DefaultMutableTreeNode Fsensor1_1_1 = new DefaultMutableTreeNode(
				"土壤水分传感器");
		DefaultMutableTreeNode Fsensor1_1_3 = new DefaultMutableTreeNode(
				"土壤水盐传感器");
		DefaultMutableTreeNode Fsensor1_2_1 = new DefaultMutableTreeNode(
				"土壤水分传感器");
		DefaultMutableTreeNode Fsensor1_2_3 = new DefaultMutableTreeNode(
				"土壤水盐传感器");
		DefaultMutableTreeNode Fway2_1 = new DefaultMutableTreeNode("根区算术平均法");
		DefaultMutableTreeNode Fway2_2 = new DefaultMutableTreeNode("根区加权平均法");
		DefaultMutableTreeNode Fsensor2_1_1 = new DefaultMutableTreeNode(
				"土壤水分传感器");
		DefaultMutableTreeNode Fsensor2_1_3 = new DefaultMutableTreeNode(
				"土壤水盐传感器");
		DefaultMutableTreeNode Fsensor2_2_1 = new DefaultMutableTreeNode(
				"土壤水分传感器");
		DefaultMutableTreeNode Fsensor2_2_3 = new DefaultMutableTreeNode(
				"土壤水盐传感器");
		DefaultTreeModel Foption = new DefaultTreeModel(fFOption);
		fFOption.add(Foption1);
		fFOption.add(Foption2);
		Fway1_1.add(Fsensor1_1_1);
		Fway1_1.add(Fsensor1_1_3);
		Fway1_2.add(Fsensor1_2_1);
		Fway1_2.add(Fsensor1_2_3);
		Foption1.add(Fway1_1);
		Foption1.add(Fway1_2);
		Fway2_1.add(Fsensor2_1_1);
		Fway2_1.add(Fsensor2_1_3);
		Fway2_2.add(Fsensor2_2_1);
		Fway2_2.add(Fsensor2_2_3);
		Foption2.add(Fway2_1);
		Foption2.add(Fway2_2);
		JTree Ftree = new JTree(Foption);
		Ftree.setFont(new Font("宋体", Font.PLAIN, 12));
		JScrollPane scrollPane_2 = new JScrollPane(Ftree);
		
		tabbedPanes.addTab("功能参数", null, scrollPane_2, null);

	}

	public static void main(String[] args) throws Exception {
		new ParaManage();
	}
}
